<script setup>
	import HeaderNavTabarSvg from '@/components/HeaderNavTabarSvg/HeaderNavTabar.vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'

	import AuditApplicationSteps from '@/components/audit/function/auditApplicationSteps.vue'
	import DescriptionAttachment from '@/components/audit/function/descriptionAttachment.vue'
	import {
		ref
	} from 'vue'
	import dayjs from 'dayjs'
	import {
		isObjectValuesNotEmpty
	} from '@/utils/objIsnull.js'

	const title = '培训会议请假单'
	const depNameRef = ref(null)
	const leaceTypeRef = ref(null)
	const leaceList = ref({
		depName: '',
		leaceType: '',
	})

	const description = ref('')


	// 打开模态床
	const toggleDept = () => {
		depNameRef.value.open() // 调用子组件的 show 方法
	}
	// 打开模态床
	const toggleLeaveType = () => {
		leaceTypeRef.value.open() // 调用子组件的 show 方法
	}

	const depNameColumns = [
		[
			'南阳分公司',
			'郑州分公司副总经理赵毅分管',
			'郑州分公司副总经理刘西锐分管',
			'新媒体信息化副总经理邱玉娥分管',
			'新媒体信息化总经理陶冶分管',
			'武汉分公司',
			'策划分公司',
			'西北分公司',
			'浙闽分公司',
			'资质管理分公司',
			'安装分公司',
			'郑州连锁策划分公司',
			'工程暖通劳务分公司',
			'车间灯箱字加工冯彦分管',
			'车间写真武桂云分管',
			'财务管理中心',
			'行政人资管理中心',
			'营销管理中心',
			'梅苑国旅',
			'南阳合作公司-朱红滨部门',
		],
	]
	const applicationTypeColumns = [
		['请假不到场', '请假晚到场', '现场转线上']
	]
	const depNameRefConfirm = (e) => {
		leaceList.value.depName = e.value[0]
	}
	const leaveTypeConfirm = (e) => {
		leaceList.value.leaceType = e.value[0]
	}

	let attchment = ref([])
	const getDesignDrawingsEmit = (emit) => {
		attchment.value = emit
	}

	const clickSave = () => {
		const RequiredItemList = JSON.parse(JSON.stringify(leaceList.value))
		RequiredItemList.description = description.value
		if (isObjectValuesNotEmpty(RequiredItemList)) {
			let params = {
				depName: leaceList.value.depName,
				leaceType: leaceList.value.leaceType,
				description: description.value,
				ruleId: 'peixunhuiyiqingjia',
				type: '培训会议请假单',
				attchment: JSON.stringify(attchment.value),
				approve: approvalProcessState.state.approvalProcess
			}
			console.log(params, '培训会议请假单params')
			// let { code } = await addAdministrativeApply(params)
			// if (code === 200) {
			//   uni.showToast({
			//     title: '提交成功',
			//     duration: 1500,
			//     icon: 'success',
			//   })
			//   setTimeout(() => {
			//     uni.navigateBack()
			//   }, 1000)
			// }
		} else {
			uni.showToast({
				title: '请输入完整数据',
				icon: 'error',
			})
		}
		// uni.showToast({
		//   title: '提交成功',
		//   duration: 1500,
		//   icon: 'success',
		// })

		// setTimeout(() => {
		//   uni.navigateBack({
		//     url: '/pages/attendance/attendancePage',
		//   })
		// }, 1000)
	}
	
	const goHistoryView = () => {
		uni.navigateTo({
			url: '/components/TypeDefineModel?type=培训会议请假单&apiName=其他',
		})
	}
	onLoad(() => {})
</script>

<template>
	<view>
		<!--    培训会议请假单  -->
		<HeaderNavTabarSvg :title="title">
			<image class="bukaSvg" src="/static/icon/auditSVG/buka.svg"  @tap="goHistoryView"></image>
		</HeaderNavTabarSvg>
		<view class="picker-content" @tap="toggleDept">
			<view class="measurement-info-list">
				<text class="info-list-left isrequired">所属部门</text>
				<view class="info-list-right">
					<view v-if="leaceList.depName" class="uni-input">{{ leaceList.depName }}</view>
					<view v-else class="uni-inputs">请选择</view>
					<i class="iconfont icon-youjiantou"></i>
				</view>
			</view>
		</view>
		<view class="picker-content" @tap="toggleLeaveType">
			<view class="measurement-info-list">
				<text class="info-list-left isrequired">申请类型</text>
				<view class="info-list-right">
					<view v-if="leaceList.leaceType" class="uni-input">{{ leaceList.leaceType }}</view>
					<view v-else class="uni-inputs">请选择</view>
					<i class="iconfont icon-youjiantou"></i>
				</view>
			</view>
		</view>
		<view class="textarea-box">
			<text class="info-list-left isrequired">具体情况描述</text>
			<textarea v-model="description" class="textinfo-list" placeholder="请输入"></textarea>
		</view>
		<uv-picker ref="depNameRef" :columns="depNameColumns" @confirm="depNameRefConfirm"></uv-picker>
		<uv-picker ref="leaceTypeRef" :columns="applicationTypeColumns" @confirm="leaveTypeConfirm"></uv-picker>
		<!--    说明附件-->
		<DescriptionAttachment />
		<!--    审批流程-->
		<AuditApplicationSteps :ruleId="'peixunhuiyiqingjia'"/>
		<!--    底部占位符-->
		<view class="blank"></view>
		<!--    保存-->
		<view class="buttonContainer">
			<button class="buttonClass" @click="clickSave">提交</button>
		</view>
	</view>
</template>

<style lang="scss" scoped>
	@import '@/static/style/index.scss';

	.bukaSvg {
		width: 32rpx;
		height: 32rpx;
	}

	.buttonContainer {
		position: fixed;
		bottom: 0;
		display: flex;
		justify-content: center;
		width: 100%;
		align-items: center;
		padding: 16rpx;
		background-color: #fff;
	}

	.buttonClass {
		display: flex;
		width: 686rpx;
		height: 72rpx;
		justify-content: center;
		align-items: center;
		background: #165dff;
		border-radius: 16rpx;
		color: #fff;
		font-size: 32rpx;
		//margin-top: 40rpx;
		overflow: hidden;
	}

	.blank {
		height: calc(72rpx + 32rpx + 20rpx);
	}

	.bukabanci {
		.info-content {
			color: #86909c !important;
		}

		.info-list-left {
			// @include font-color-auxiliary;
			color: #86909c !important;
		}
	}

	.textarea-box {
		background: #fff;
		padding: 20rpx;
		margin-top: 20rpx;

		.info-list-left {
			// @include font-color-auxiliary;
			color: #1d2129;
			font-size: $font-size-base;
		}

		.textinfo-list {
			margin-top: 20rpx;
			width: 100%;
			height: 200rpx;
		}
	}

	.popup-content {
		background: #f7f8fa;

		.header-box {
			padding: 30rpx 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			p {
				color: #1d2129;
				font-size: 34rpx;
				font-weight: 500;
			}

			.module-image-ba {
				border-radius: 32rpx;
				background: #f2f3f5;
				width: 45rpx;
				height: 45rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				image {
					width: 32rpx;
					height: 32rpx;
				}
			}
		}

		.card-list {
			display: flex;
			align-items: center;
			flex-direction: column;
			padding: 20rpx 30rpx;
			box-sizing: border-box;

			.list {
				box-shadow: 0 4rpx 16rpx 0 #0000000d;
				box-sizing: border-box;
				width: 100%;
				background: #fff;
				padding: 16rpx 24rpx;
				border-radius: 8rpx;
				margin-bottom: 10rpx;

				h4 {
					color: #1d2129;
					font-size: 32rpx;
					font-weight: 400;
				}

				p {
					color: #86909c;
					font-size: 24rpx;
					font-weight: 400;
					margin-top: 10rpx;
				}
			}
		}
	}
	
	.uni-inputs {
		color: #86909c !important;
	}

	.measurement-info-list {
		@include flex($align: center, $justify: space-between);
		padding: $spacing-row-base;
		background: #fff;
		margin-top: 16rpx;

		.info-list-left {
			// @include font-color-auxiliary;
			color: #1d2129;
			font-size: $font-size-base;
		}

		.info-list-right {
			@include flex($align: center);

			.info-content {
				@include textStyleBase;
				font-size: 34rpx;
			}

			.iconfont {
				margin-left: 16rpx;
				// @include font-color-auxiliary;
				color: $uni-fc-fu-lin;
			}
		}

		.unit {
			// @include font-color-auxiliary;
			color: $uni-fc-fu-lin;
		}
	}
</style>